﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using FineUI;
using SDLITS.Common;
using SDLITS.Model;
using MySoft.Data;
namespace SDLITS.Web.Basic
{
    public partial class DoorChange : CommonBase
    {
        #region 页面初始化
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }
        #endregion

        #region 读取数据


        private void LoadData()
        {
            int id = 0;
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                id = int.Parse(Request["id"]);
            }
            if (id > 0)
            {
                Door Tm = SDDbSession.Default.From<Door>().Where(Door._.DoorID == id).ToFirst();
                txt_Name.Text = Tm.DoorName;
                txt_fax.Text = Tm.Description;
                txt_IP.Text = Tm.IPAddr;
            }
        }
        #endregion

        #region 保存数据
        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            int returnvalue = 0;
            Door Tm = new Door();
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                Tm.DoorID = int.Parse(Request["id"]);
                Tm.Attach();
                Tm.DoorName = txt_Name.Text;
                Tm.IPAddr = txt_IP.Text;
                Tm.Description = txt_fax.Text;
                returnvalue = SDDbSession.Default.Update<Door>(Tm);
            }
            else
            {
                ModelLoginUser user = Session["LoginUser"] as ModelLoginUser;
                Tm.DeAttach();
                Tm.DoorName = txt_Name.Text;
                Tm.Description = txt_fax.Text;
                Tm.IPAddr = txt_IP.Text;
                Tm.StatusID =1;
                Tm.CreateDate = DateTime.Now;
                Tm.CreateUserID = user.UserID;
                returnvalue = SDDbSession.Default.Insert<Door>(Tm);
            }
            if (returnvalue > 0)
            {
                PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
            }
        }
        #endregion
    }
}